<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script src="./scripts/jquery-3.6.1.js"></script>
        <style>
            .box1 {
                float: left;
                width: 100px;
                height: 100px;
                border: 1px red solid;
                margin: 10px;
            }
        </style>

        <script>
            $(function () {
                $("#btn01").click(function () {
                    //     $(".box1").css("background-color", "#bfa")

                    // eq()用来获取jQuery对象中指定索引的元素
                    // first() 获取第一个元素
                    // last() 获取最后一个元素
                    // even() 获取索引为偶数的元素
                    // odd() 获取索引为奇数的元素
                    // slice() 切片
                    // $(".box1").eq(-1).css("background-color", "#bfa")
                    // $(".box1").even().css("background-color", "#bfa")

                    // $(".box1").slice(1, 3).css("background-color", "#bfa")

                    $(".box1").filter(".a").css("background-color", "#bfa")

                    // $(".box1")[0]
                    // $(".box1").get(0)
                })
            })
        </script>
    </head>
    <body>
        <button id="btn01">点我</button>

        <hr />

        <div class="box1"></div>
        <div class="box1"></div>
        <div class="box1"></div>
        <div class="box1 a"></div>
        <div class="box1 a"></div>
        <div class="box1 a"></div>
        <div class="box1"></div>
        <div class="box1 a"></div>
        <div class="box1"></div>
        <div class="box1"></div>
    </body>
</html>
